﻿package org.xhs.report.common.adv
{
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import flash.utils.*;

    public class CountDown extends Sprite
    {
        public var bgWidth:Number = 117;
        public var bgHeight:Number = 26;
        public var bgColor:uint = 0;
        public var bgAlpha:Number = 0.5;
        public var dynamicText:TextField;
        private var _duration:int = 0;
        private var _currentCount:int = 0;
        private var _countDownTimer:Timer;

        public function CountDown(param1:Number)
        {
            graphics.clear();
            graphics.beginFill(this.bgColor, this.bgAlpha);
            graphics.drawRect(0, 0, this.bgWidth, this.bgHeight);
            graphics.endFill();
            mouseChildren = false;
            mouseEnabled = false;
            this.duration = Math.floor(param1);
            this._countDownTimer = new Timer(1000);
            this._countDownTimer.addEventListener(TimerEvent.TIMER, this.countDown);
            return;
        }// end function

        private function countDown(event:TimerEvent) : void
        {
            if (!this.dynamicText)
            {
                this.dynamicText = new TextField();
                this.dynamicText.autoSize = "right";
                addChild(this.dynamicText);
            }
            var _loc_2:String = this;
            var _loc_3:* = this._currentCount - 1;
            _loc_2._currentCount = _loc_3;
            this.dynamicText.htmlText = "<FONT SIZE=\'12\' COLOR=\'#FFFFFF\' FACE=\'宋体\'>广告剩余<FONT SIZE=\'14\' COLOR=\'#f47104\' FACE=\'Arial\'><b> " + this._currentCount.toString() + " </b></FONT>秒</FONT>";
            this.dynamicText.x = (this.bgWidth - this.dynamicText.width) / 2;
            this.dynamicText.y = (this.bgHeight - this.dynamicText.height) / 2;
            return;
        }// end function

        public function start() : void
        {
            if (!this.duration)
            {
                return;
            }
            this._countDownTimer.reset();
            this._countDownTimer.start();
            this.countDown(null);
            return;
        }// end function

        public function get duration() : int
        {
            return this._duration;
        }// end function

        public function set duration(param1:int) : void
        {
            this._duration = param1;
            this._currentCount = this._duration;
            return;
        }// end function

    }
}
